--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit f0f5bb16aab058cdca21c9908f77b7bc83323287
Parents : b720efb
Author : Ivan <e46112d44649266d71fe2193e00a4710>
Signature : T66BB85Valid, signed by author
Date : 2026-07-19T05:04:55-05:00
test: add tests to reject symlink escape and enforce hash length in identity management
Changes
3 files changed, 23 insertions(+), 0 deletions(-)
Diff
diff --git a/meshchatx.rsm b/meshchatx.rsm
index 11ef1008..8ace4ccf 100644
Binary files a/meshchatx.rsm and b/meshchatx.rsm differ
diff --git a/tests/backend/test_safe_path_under_dir.py b/tests/backend/test_safe_path_under_dir.py
index 056a202e..edbd6f06 100644
--- a/tests/backend/test_safe_path_under_dir.py
+++ b/tests/backend/test_safe_path_under_dir.py
@@ -21,3 +21,14 @@ def test_safe_path_under_dir_rejects_nul_and_dot(tmp_path):
assert safe_path_under_dir(str(tmp_path), "a\x00b.opus") is None
assert safe_path_under_dir(str(tmp_path), "..") is None
assert safe_path_under_dir(str(tmp_path), "") is None
+
+
+def test_safe_path_under_dir_rejects_symlink_escape(tmp_path):
+ """realpath containment must reject basename symlinks that leave the jail."""
+ outside = tmp_path / "outside.secret"
+ outside.write_bytes(b"secret")
+ jail = tmp_path / "jail"
+ jail.mkdir()
+ link = jail / "escape.opus"
+ link.symlink_to(outside)
+ assert safe_path_under_dir(str(jail), "escape.opus") is None
diff --git a/tests/backend/test_security_path_jail_regressions.py b/tests/backend/test_security_path_jail_regressions.py
index d5966913..e34aee23 100644
--- a/tests/backend/test_security_path_jail_regressions.py
+++ b/tests/backend/test_security_path_jail_regressions.py
@@ -45,6 +45,18 @@ def test_delete_identity_rejects_path_traversal(tmp_path):
assert marker.exists()
+def test_delete_identity_rejects_wrong_length_hex(tmp_path):
+ """Hash length must be enforced even when the path would stay in-tree."""
+ manager = IdentityManager(str(tmp_path))
+ short_hash = "ab" * 15
+ target = tmp_path / "identities" / short_hash
+ target.mkdir(parents=True)
+ (target / "identity").write_bytes(b"x")
+ with pytest.raises(ValueError, match="Invalid identity hash"):
+ manager.delete_identity(short_hash, current_identity_hash=None)
+ assert target.exists()
+
+
def test_delete_identity_removes_only_canonical_dir(tmp_path):
manager = IdentityManager(str(tmp_path))
identity_hash = "cd" * 16
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────